package com.we.wecc.us.api.controller;

import java.util.Map;

import javax.annotation.Resource;

import com.we.wecc.us.db.model.UserAddress;
import com.we.wecc.us.db.model.UserCoinAddress;
import com.we.wecc.us.mid.model.in.UserAddressIn;
import com.we.wecc.us.mid.model.in.UserCoinAddressIn;
import com.x.share.db.model.Pagination;
<<<<<<< HEAD

=======
import com.x.share.mid.prop.ShareProperties;
>>>>>>> c19c46d0506427ba51599706f41193058ae21d65
import org.springframework.web.bind.annotation.*;

import com.we.wecc.us.db.model.User;
import com.we.wecc.us.mid.service.UserService;
import com.x.share.api.controller.BaseController;
import com.x.share.mid.exception.HelperException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(value = "用户接口")
@RestController
@RequestMapping("/wecc/us")
public class UserController extends BaseController{

	@Resource
	UserService userService;
	
	@ApiOperation(value = "测试用户", notes= "测试用户", response = User.class)
	@RequestMapping(value = "/testUser", method = { RequestMethod.GET})
	public @ResponseBody Map<String, Object> userService(
			@ApiParam(value = "用户id") @RequestHeader("userId") Long userId,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
		User user = userService.getUserDetail(userId);
		return success(user);
	}

	@ApiOperation(value = "添加或修改用户提币地址", notes= "添加或修改用户提币地址", response = UserCoinAddress.class)
	@RequestMapping(value = "/usCoinAddress/saveUserCoinAddress", method = { RequestMethod.POST})
	public @ResponseBody Map<String, Object> saveUserCoinAddress(
			@RequestBody UserCoinAddressIn in,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
			) throws HelperException {
		UserCoinAddress userCoinAddress = userService.saveCoinAddress(in);
		return success(userCoinAddress);
	}

	@ApiOperation(value = "获取用户提币地址列表", notes= "获取用户提币地址列表", response = UserCoinAddress.class)
	@RequestMapping(value = "/usCoinAddress/getUserCoinAddressList", method = { RequestMethod.GET})
	public @ResponseBody Map<String, Object> getUserCoinAddressList(
			@ApiParam(value = "用户id") @RequestParam("userId") Long userId,
			@ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
			@ApiParam(value = "每页记录数", defaultValue = "5") @RequestParam("ps") Integer pageSize,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
			) throws HelperException {
		Pagination<UserCoinAddress> page = userService.getUserCoinAddressList(userId, pageNo, pageSize);
		return success(page);
	}

	@ApiOperation(value = "删除用户提币地址", notes= "删除用户提币地址", response = Boolean.class)
	@RequestMapping(value = "/usCoinAddress/deleteUserCoinAddress", method = { RequestMethod.DELETE})
	public @ResponseBody Map<String, Object> deleteUserCoinAddress(
			@ApiParam(value = "用户提币地址id") @RequestParam("uaId") Long uaId,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
	) throws HelperException {
		Boolean flag = userService.deleteUserCoinAddress(uaId);
		return success(flag);
	}

	@ApiOperation(value = "获取上次提币地址", notes= "获取上次提币地址", response = Map.class)
	@RequestMapping(value = "/usCoinAddress/getLastCoinAddress", method = { RequestMethod.GET})
	public @ResponseBody Map<String, Object> getLastCoinAddress(
			@ApiParam(value = "用户id") @RequestParam("userId") Long userId,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
	) throws HelperException {
		Map<String,Object> i = userService.getLastCoinAddress(userId);
		return success(i);
	}

	@ApiOperation(value = "添加或修改用户收获地址", notes= "添加或修改用户收获地址", response = UserCoinAddress.class)
	@RequestMapping(value = "/usAddress/saveUserAddress", method = { RequestMethod.POST})
	public @ResponseBody Map<String, Object> saveUserAddress(
			@RequestBody UserAddressIn in,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
	) throws HelperException {
		UserAddress userAddress = userService.saveAddress(in);
		return success(userAddress);
	}

	@ApiOperation(value = "获取用户地址列表", notes= "获取用户地址列表", response = UserAddress.class)
	@RequestMapping(value = "/usAddress/getUserAddressList", method = { RequestMethod.GET})
	public @ResponseBody Map<String, Object> getUserAddressList(
			@ApiParam(value = "用户id") @RequestParam("userId") Long userId,
			@ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
			@ApiParam(value = "每页记录数", defaultValue = "5") @RequestParam("ps") Integer pageSize,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
	) throws HelperException {
		Pagination<UserAddress> page = userService.getUserAddressList(userId, pageNo, pageSize);
		return success(page);
	}

	@ApiOperation(value = "删除用户地址", notes= "删除用户地址", response = Boolean.class)
	@RequestMapping(value = "/usAddress/deleteUserAddress", method = { RequestMethod.DELETE})
	public @ResponseBody Map<String, Object> deleteUserAddress(
			@ApiParam(value = "用户地址id") @RequestParam("uaId") Long uaId,
			@ApiParam(value = "应用id") @RequestHeader("appId") String appId,
			@ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
	) throws HelperException {
		Boolean flag = userService.deleteUserAddress(uaId);
		return success(flag);
	}
}
